import type { expressionItemsType } from "./types";
type keyofBracketEnumType = keyof typeof basicBracketEnum;

import { Operator } from "@base/Operator";
import { BracketLeft, BracketRight } from "@base/Bracket";
import { basicBracketEnum } from "@base/enum";
import { Editor } from "@base/Editor";
import { EditorType } from "@base/Editor/types";

/**
 * 
 * @param target 被判断的目标
 * @param types 可选参数，判断是那类括号"left" | "right"
 * @returns 是否是目标括号
 */
// function isBracket(target: BracketType | OperatorType): boolean;
export function isBracket(target: expressionItemsType | string | EditorType, type?: keyofBracketEnumType): boolean {
    if (target instanceof BracketLeft || target instanceof BracketRight) {
        if (type === undefined) return true;
        return target.getBasic() === basicBracketEnum[type];
    }
    return false;
}

/**
 * 
 * @param target 被判断的目标
 * @returns 是否是操作符的实例
 */
export function isOperator(target: expressionItemsType | string | EditorType) {
    return target instanceof Operator;
}

export function isEditor(target: expressionItemsType | string | EditorType) {
    return target instanceof Editor;
}